<template>
  <div>
    <Main :type="'form'">
      <Title :title="'打印机设置'"></Title>
      <el-row class="form_wrap">
        <el-col :span="24">
          <el-form ref="form" label-width="180px" :rules="rules" :model="form">
            <el-form-item label="打印机名称" prop="printerName">
              <el-input
                v-model="form.printerName"
                placeholder="请输入打印机名称"
                class="form-input"
                size="medium"
              ></el-input>
            </el-form-item>
            <el-form-item label="打印机类型" prop="opValue">
              <el-select
                v-model="form.opValue"
                class="form-input"
                placeholder="请选择"
              >
                <el-option
                  v-for="(item, index) in options"
                  :key="index"
                  :value="item.id"
                  :label="item.type_name"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="打印机终端号" prop="printerNum">
              <el-input
                v-model="form.printerNum"
                placeholder="请输入打印机终端号"
                class="form-input"
                size="medium"
              ></el-input>
            </el-form-item>
            <el-form-item label="打印机ID" prop="printerID">
              <el-input
                v-model="form.printerID"
                placeholder="请输入设置打印机ID"
                class="form-input"
                size="medium"
              ></el-input>
            </el-form-item>
            <el-form-item label="打印机密钥" prop="printerSecretKey">
              <el-input
                v-model="form.printerSecretKey"
                placeholder="请输入设置打印机密钥"
                class="form-input"
                size="medium"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <Footer>
        <div>
          <el-button plain @click="$emit('out')">取 消</el-button>
          <el-button type="primary" @click="sumbit">保 存</el-button>
        </div>
      </Footer>
    </Main>
  </div>
</template>
<script>
import { SETPRINTS, PRINTSTYPELIST } from "../service";

export default {
  data() {
    return {
      form: {
        printerName: "",
        opValue: "",
        printerNum: "",
        printerID: "",
        printerSecretKey: ""
      },
      options: [],
      rules: {
        printerName: [
          { required: true, message: "请输入打印机名称", trigger: "blur" }
        ],
        opValue: [
          { required: true, message: "请选择打印机类型", trigger: "chang" }
        ],
        printerNum: [
          { required: true, message: "请输入打印机终端号", trigger: "blur" }
        ],
        printerID: [
          { required: true, message: "请输入设置打印机ID", trigger: "blur" }
        ],
        printerSecretKey: [
          { required: true, message: "请输入设置打印机密钥", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getSelect();
  },
  methods: {
    async getSelect() {
      await PRINTSTYPELIST().then(res => {
        let { code, data } = res;
        if (code === 200) {
          this.options = data;
        } else {
          this.options = [];
          // this.$message.error(msg)
        }
      });
    },
    async sumbit() {
      await this.$refs["form"].validate(valid => {
        if (valid) {
          let prams = {
            flag: "add",
            type_id: this.opValue,
            key: this.printerSecretKey,
            machinecode: this.printerNum,
            printname: this.printerName,
            appid: this.printerID
          };
          SETPRINTS(prams).then(() => {
            // let { code, data, msg } = res
            // if (code === 200) {
            // }
          });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped></style>
